package com.edu.app.service.impl.linkservices;

import com.edu.app.bean.core.SysPermission;
import com.edu.app.bean.core.SysUser;
import com.edu.app.bean.linkbeans.SysRolePermission;

import com.edu.app.mapper.linkmappers.SysRolePermissionMapper;
import com.edu.app.service.impl.SysBaseServiceImpl;
import com.edu.app.service.sys.linkservices.SysRolePermissionService;
import org.apache.shiro.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class SysRolePermissionServiceImpl extends SysBaseServiceImpl<SysRolePermission,SysRolePermissionMapper> implements SysRolePermissionService {
    @Autowired
    private SysRolePermissionMapper sysRolePermissionMapper;



    @Override
    public Integer add(SysRolePermission sysRolePermission){
        //重要：取当前session登录的用户名
        SysUser user = (SysUser) SecurityUtils.getSubject().getPrincipal();

        sysRolePermission.initializeSystemColumns(user.getUsername());
        return sysRolePermissionMapper.insert(sysRolePermission);
    }


    @Override
    public List<SysPermission> getPermissionListByRoleId(Integer id){

        List<SysPermission> sysPermission = sysRolePermissionMapper.getPermissionByRoleId(id);
        return sysPermission;
    }

    @Override
    public Integer getRolePermissionId(Integer role_id, Integer permission_id){
        return sysRolePermissionMapper.getRolePermissionId(role_id, permission_id);
    }
}
